package com.sxf.biz.customer.controller;

import com.sxf.auth.login.service.UserService;
import com.sxf.auth.login.vo.AddCoordinateApproverReq;
import com.sxf.auth.login.vo.AddUserRes;
import com.sxf.auth.login.vo.ResetPasswordReq;
import com.sxf.biz.coordinator.service.CoordinatorService;
import com.sxf.biz.coordinator.vo.CoordinatorInfoReq;
import com.sxf.biz.coordinator.vo.CoordinatorInfoRes;
import com.sxf.biz.customer.service.CustomerService;
import com.sxf.biz.customer.vo.*;
import com.sxf.common.param.ResultInfo;
import com.sxf.core.db.page.Pagination;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: TODO
 * @Author Leo
 * @date 2024/3/1820:24
 */
@RestController
@Api(value = "客户端相关", tags = { "客户端相关" })
@Validated
@RequestMapping("/cm")
public class CustomerController {

    @Autowired
    CustomerService customerService;
    @Autowired
    UserService userService;
    @Autowired
    CoordinatorService coordinatorService;

    @ApiOperation(value = "查询协调员/审核员列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/staff/getByPage")
    public ResultInfo<Pagination<StaffListRes>> getStaffList(@Validated @RequestBody StaffListReq req){
        return ResultInfo.success(customerService.getCustomerStaffByPage(req));
    }

    @ApiOperation(value = "新增协调员/审核员", produces = "application/json", httpMethod = "POST")
    @PostMapping("/staff/add")
    public ResultInfo<AddUserRes> addStaff(@Validated @RequestBody AddCoordinateApproverReq req){
        return ResultInfo.success(customerService.addCustomerStaff(req));
    }

    @ApiOperation(value = "启用禁用协调员/审核员", produces = "application/json", httpMethod = "POST")
    @PostMapping("/staff/toggle")
    public ResultInfo<Boolean> enableOrDisable(@Validated @RequestBody ToggleStaffReq req){
        return ResultInfo.success(customerService.toggleUserStatus(req));
    }

    @ApiOperation(value = "重置协调员/审核员用户密码", produces = "application/json", httpMethod = "POST")
    @PostMapping("/staff/resetPwd")
    public ResultInfo<Boolean> resetPwd(@Validated @RequestBody ResetPasswordReq req){
        return ResultInfo.success(userService.resetPassword(req));
    }

    @ApiOperation(value = "查询中心列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/center/getByPage")
    public ResultInfo<Pagination<CenterListRes>> getCenterList(@Validated @RequestBody CenterListReq req){
        return ResultInfo.success(customerService.getCenterListByPage(req));
    }

    @ApiOperation(value = "添加中心", produces = "application/json", httpMethod = "POST")
    @PostMapping("/center/add")
    public ResultInfo<Boolean> addCenter(@Validated @RequestBody AddCenterReq req){
        return ResultInfo.success(customerService.addCenter(req));
    }

    @ApiOperation(value = "删除中心", produces = "application/json", httpMethod = "POST")
    @PostMapping("/center/delete")
    public ResultInfo<Boolean> deleteCenter(@Validated @RequestBody CenterDeleteReq req){
        return ResultInfo.success(customerService.deleteCenter(req));
    }

    @ApiOperation(value = "查询项目列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/getByPage")
    public ResultInfo<Pagination<ProjectListRes>> getProjectList(@Validated @RequestBody ProjectListReq req){
        return ResultInfo.success(customerService.getProjectListByPage(req));
    }

    @ApiOperation(value = "查询项目详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/getDetail")
    public ResultInfo<ProjectDetailRes> getProjectDetail(@Validated @RequestBody ProjectDetailReq req){
        return ResultInfo.success(customerService.getProjectDetail(req));
    }

    @ApiOperation(value = "添加项目", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/add")
    public ResultInfo<AddProjectRes> addProject(@Validated @RequestBody AddProjectReq req){
        return ResultInfo.success(customerService.addProject(req));
    }

    @ApiOperation(value = "修改项目", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/edit")
    public ResultInfo<Boolean> editProject(@Validated @RequestBody EditProjectReq req){
        return ResultInfo.success(customerService.editProject(req));
    }

    @ApiOperation(value = "结束项目", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/finish")
    public ResultInfo<Boolean> finishProject(@Validated @RequestBody ProjectDetailReq req){
        return ResultInfo.success(customerService.finishProject(req));
    }

    @ApiOperation(value = "项目对应受试者列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/subjectsList")
    public ResultInfo<Pagination<SubjectsListRes>> getSubjectsList(@Validated @RequestBody SubjectListReq req){
        return ResultInfo.success(customerService.getSubjectList(req));
    }

//    @ApiOperation(value = "项目对应中心列表", produces = "application/json", httpMethod = "POST")
//    @PostMapping("/project/centerList")
//    public ResultInfo<Pagination<CenterListRes>> getProjectCenterList(@Validated @RequestBody CenterListReq req){
//        return ResultInfo.success(customerService.getCenterListByPage(req));
//    }

    @ApiOperation(value = "添加项目中心", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/addCenter")
    public ResultInfo<Boolean> addCenter4Project(@Validated @RequestBody AddCenterForProjectReq req){
        return ResultInfo.success(customerService.addCenter4project(req));
    }

    @ApiOperation(value = "编辑项目中心", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/editCenter")
    public ResultInfo<Boolean> editCenter4Project(@Validated @RequestBody EditCenterForProjectReq req){
        return ResultInfo.success(customerService.editCenter4project(req));
    }

    @ApiOperation(value = "查询项目下中心详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/project/getCenterDetail")
    public ResultInfo<ProjectCenterDetailRes> getCenterDetail(@Validated @RequestBody ProjectCenterDetailReq req){
        return ResultInfo.success(customerService.getProjectCenterDetail(req));
    }

    @ApiOperation(value = "结算单列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/settle/getByPage")
    public ResultInfo<SettlePageRes> getSettleList(@Validated @RequestBody SettleListReq req){
        return ResultInfo.success(customerService.getSettleListByPage(req));
    }

    @ApiOperation(value = "结算单详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/settle/getDetail")
    public ResultInfo<SettleDetailRes> getSettleDetail(@Validated @RequestBody SettleDetailReq req){
        return ResultInfo.success(customerService.getSettleDetail(req));
    }

    @ApiOperation(value = "受试者列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/subjects/getByPage")
    public ResultInfo<Pagination<SubjectsListRes>> getSubjectsByPage(@Validated @RequestBody SubjectListReq req){
        return ResultInfo.success(customerService.getSubjectsByPage(req));
    }

    @ApiOperation(value = "根据手机号查询协调员用户信息", produces = "application/json", httpMethod = "POST")
    @PostMapping("/getCoordinatorByMobile")
    public ResultInfo<CoordinatorInfoRes> updateUserInfo(@Validated @RequestBody CoordinatorInfoReq req){
        return ResultInfo.success(coordinatorService.getCoordinatorInfoByMobile(req));
    }
}
